<template>
  <el-form-item
    :label="label"
    :label-width="labelWidth"
    :prop="props.data.field"
    :required="props.data.required"
    :rules="props.data.rules"
  >
    <el-date-picker
      v-model="val"
      type="daterange"
      range-separator="至"
      :value-format="valueFormat"
      :style="{ width: `${props.data.compWidth || 100}%` }"
      :start-placeholder="props.data.bPlaceholder"
      :end-placeholder="props.data.ePlaceholder"
      :clearable="props.data.clearable"
      :readonly="props.data.readonly"
      :disabled="props.data.disabled"
    />
  </el-form-item>
</template>

<script setup lang="ts">
import { computed } from 'vue'
import { ElFormItem, ElDatePicker } from 'element-plus'
import { useProps, useValue } from '../../common-props/hooks'
import { dateFormatType } from '../../supports/utils'

const props = defineProps<{ data: Record<string, any>; form: Record<string, any> }>()
const emits = defineEmits(['valueChange'])

const { label, labelWidth } = useProps(props)
const { val } = useValue(props, emits)

const valueFormat = computed(() => dateFormatType(props.data.type))
</script>

<style lang="scss" scoped></style>
